package com.project.business.memcache;

import java.util.Date;

import com.danga.MemCached.MemCachedClient;

/**
 * 
 * @author xiaoxiaosu
 * 
 */
public class MemcacheParent {
	private MemCachedClient memCachedClient;


	/**
	 * get value from constant.properties
	 */
	protected final String CACHE_SWITCH = "open";
	protected final int CACHE_TIME = 300;

	// public final
	/**************** Memcache functions ********************/
	public void add(String key, Object value) {
		memCachedClient.set(key, value);
	}

	public void add(String key, Object value, int milliseconds) {
		memCachedClient.set(key, value, milliseconds);
	}

	public void add(String key, Object value, Date date) {
		memCachedClient.set(key, value, date);
	}

	public void remove(String key) {
		memCachedClient.delete(key);
	}

	public void remove(String key, int milliseconds) {
		memCachedClient.delete(key, milliseconds, new Date());
	}

	public void update(String key, Object value, int milliseconds) {
		memCachedClient.replace(key, value, milliseconds);
	}

	public void update(String key, Object value) {
		memCachedClient.replace(key, value);
	}

	public Object get(String key) {
		return memCachedClient.get(key);
	}

	/***************************************************************/
	/**
	 * 是否做缓存
	 * 
	 * @return
	 */
	private boolean isCached() {
		if (CACHE_SWITCH.equals("open")) {
			return true;
		}
		return false;
	}

	/************** SET & GET *****************/
	public MemCachedClient getMemCachedClient() {
		return memCachedClient;
	}

	public void setMemCachedClient(MemCachedClient memCachedClient) {
		this.memCachedClient = memCachedClient;
	}

	// public Object get
}
